package com.ruoyi.web.controller.bargain;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bargain.domain.Bargain;
import com.ruoyi.bargain.service.IBargainService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.base.AjaxResult;

/**
 * 砍价活动 信息操作处理
 * 
 * @author lzy
 * @date 2019-03-07
 */
@Controller
@RequestMapping("/bargain/bargain")
public class BargainController extends BaseController
{
    private String prefix = "bargain/bargain";
	
	@Autowired
	private IBargainService bargainService;
	
	@RequiresPermissions("bargain:bargain:view")
	@GetMapping()
	public String bargain()
	{
	    return prefix + "/bargain";
	}
	
	/**
	 * 查询砍价活动列表
	 */
	@RequiresPermissions("bargain:bargain:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Bargain bargain)
	{
		startPage();
        List<Bargain> list = bargainService.selectBargainList(bargain);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出砍价活动列表
	 */
	@RequiresPermissions("bargain:bargain:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Bargain bargain)
    {
    	List<Bargain> list = bargainService.selectBargainList(bargain);
        ExcelUtil<Bargain> util = new ExcelUtil<Bargain>(Bargain.class);
        return util.exportExcel(list, "bargain");
    }
	
	/**
	 * 新增砍价活动
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存砍价活动
	 */
	@RequiresPermissions("bargain:bargain:add")
	@Log(title = "砍价活动", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Bargain bargain)
	{		
		return toAjax(bargainService.insertBargain(bargain));
	}

	/**
	 * 修改砍价活动
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		Bargain bargain = bargainService.selectBargainById(id);
		mmap.put("bargain", bargain);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存砍价活动
	 */
	@RequiresPermissions("bargain:bargain:edit")
	@Log(title = "砍价活动", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Bargain bargain)
	{		
		return toAjax(bargainService.updateBargain(bargain));
	}
	
	/**
	 * 删除砍价活动
	 */
	@RequiresPermissions("bargain:bargain:remove")
	@Log(title = "砍价活动", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(bargainService.deleteBargainByIds(ids));
	}
	
}
